package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree;


import dk.mirasola.systemtraining.bridgewidgets.shared.model.Distribution;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.Seat;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape.Shape;

public final class ShapeDistributionFilter extends DistributionFilterGroupItem {
    private Seat seat = Seat.NORTH;
    private Shape shape = Shape.SHAPE_4333;

    public Seat getSeat() {
        return seat;
    }

    public void setSeat(Seat seat) {
        if (seat == null) {
            throw new NullPointerException();
        }
        this.seat = seat;
    }


    public Shape getShape() {
        return shape;
    }


    public void setShape(Shape shape) {
        if (shape == null) {
            throw new NullPointerException();
        }
        this.shape = shape;
    }


    protected boolean matchesInternal(Distribution distribution) {
        return getShape().match(distribution.getHand(seat));
    }

    @Override
    public String toString() {
        String res = "Shape(" + shape + "," + seat + ")";
        if (getInverted()) {
            return "NOT " + res;
        }
        return res;
    }

    @Override
    public boolean isCopy(GroupItem groupItem) {
        if (!super.isCopy(groupItem)) return false;
        if (!(groupItem instanceof ShapeDistributionFilter)) return false;

        ShapeDistributionFilter that = (ShapeDistributionFilter) groupItem;
        return seat == that.seat && shape.equals(that.shape);
    }

    @Override
    public ShapeDistributionFilter copy() {
        ShapeDistributionFilter copy = new ShapeDistributionFilter();
        copy.setInverted(this.getInverted());
        copy.seat = this.seat;
        copy.shape = this.shape;
        return copy;
    }
}
